package crc

//CRC16 计算 data CRC码值
func CRC16(data []byte) (crc uint16) {
	crc = 0
	l := len(data)
	if l > 0 {
		crc = 0xffff
		for i := 0; i < l; i++ {
			crc = crc ^ uint16(data[i])
			for j := 0; j < 8; j++ {
				if (crc & 1) != 0 {
					crc = (crc >> 1) ^ 0xa001
				} else {
					crc = crc >> 1
				}
			}
		}
	}
	return
}
